package com.dd.servlet;

import com.google.gson.Gson;
import com.dd.domain.Product;
import com.dd.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class SProductAtcion extends HttpServlet {
    boolean flag =false;
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        int pagesize = 5;

        ProductService ps = new ProductService();
        List<Product> data = ps.findByLimit(0,pagesize);
        Gson gson=new Gson();
        String info = gson.toJson(data);
        System.out.println(info);

        // session共享
        HttpSession session = request.getSession();
        session.setAttribute("productdata",data);


        response.sendRedirect("products.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
